package com.zheng.api.server.controller.task;

import com.zheng.api.server.service.task.TimeoutOrderAutoCloseTaskService;
import com.zheng.api.server.service.task.TimeoutOrderRemindTaskService;
import com.zheng.business.common.constant.BusinessConstant;
import com.zheng.common.base.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lvg EMIAL：<a href="mailto:weiguo.liang@gh-ca.com">weiguo.liang@gh-ca.com</a> <br>
 * @version 1.0 <br>
 * @Company: GH-CA<br>
 * @ClassName: BusinessHttpTaskController <br>
 * @Description: TODO <br>
 * @date 2019/8/8 11:52<br>
 **/
@RestController
@RequestMapping("/task/timeout")
@Api(value = "超时任务调度控制器", description = "超时任务调度控制器")
public class OrderTimeoutHttpTaskController extends BaseController {

    @Autowired
    TimeoutOrderAutoCloseTaskService timeoutOrderAutoCloseTaskService;
    @Autowired
    TimeoutOrderRemindTaskService timeoutOrderRemindTaskService;
    /**
     * 每天中午自动结算超时订单
     * @param request
     * @return
     */
    @ApiOperation(value = "自动结算超时订单任务")
    @RequestMapping(value = "/orderClose", method = {RequestMethod.POST})
    public Object amount( HttpServletRequest request) {
        String d = request.getParameter("d"); //大于指定天数的时间，如100
        return timeoutOrderAutoCloseTaskService.doBusinessOrderCloseTask(d);
    }

    /**
     * 每天晚上提醒待归还订单
     * @param request
     * @return
     */
    @ApiOperation(value = "超时订单提前提醒任务")
    @RequestMapping(value = "/orderRemind", method = {RequestMethod.POST})
    public Object monthAmount( HttpServletRequest request) {
        String d = request.getParameter("d"); //如提前3天
        return timeoutOrderRemindTaskService.doBusinessOrderRemindTask(d);
    }

}
